package entities;

import play.db.ebean.Model;
import play.db.jpa.JPA;
import play.db.jpa.Transactional;

import javax.persistence.*;

import java.io.Serializable;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: eagami
 * Date: 01/12/13
 * Time: 00:33
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name="Object")
public class Objects extends Model implements Serializable{


    /**
     *
     */
    private static final long serialVersionUID = -1215089218028990122L;

    private Long id;
    private String name;
    private String description;
    private Integer objectId;
    private Tag tag;


    public static Finder<Long, Objects> find = new Finder<Long, Objects>(
            Long.class, Objects.class
    );


    public Objects() {
    }

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="Object_sequence")
    @SequenceGenerator(
            name="Object_sequence",
            sequenceName="dbo.Object_sequence"
    )
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="Name",unique=false,length=20,nullable=true)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name="Description",unique=false,length=20,nullable=true)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name="Object_ID",unique=false,length=20,nullable=true)
    public Integer getObjectId() {
        return objectId;
    }

    public void setObjectId(Integer objectId) {
        this.objectId = objectId;
    }

    @OneToOne(targetEntity = Tag.class)
    @JoinColumn(
            name="TAG_ID", unique=true, nullable=false, updatable=false)
    public Tag getTag() {
        return tag;
    }

    public void setTag(Tag tag) {
        this.tag = tag;
    }

    @Transactional
    public static List<Objects> getAllObjects(){
        return Objects.find.all();
    }

    @Override
    @Transactional
    public void save() {
        JPA.em().merge(this);
    }
}
